//
// Created by cychen on 2023/3/7.
//

#include <string>
#include <set>
#include <algorithm>
#include "../include/Utils.h"
#include "../include/Word.h"

Word::Word(const std::string &_str) : str(_str) {
    this->id = -1;
    this->str = _str;
    this->begin = char2int(_str[0]);
    this->end = char2int(_str.back());
    this->length = (int) _str.length();
    this->toSccId = -1;
}

Word::Word() {
    this->id = -1;
    this->str = std::string("");
    this->begin = this->end = this->length = 0;
    this->toSccId = -1;
}

const std::string &Word::getStr() const {
    return str;
}

int Word::getBegin() const {
    return begin;
}

int Word::getAnEnd() const {
    return end;
}

int Word::getLength() const {
    return length;
}

void Word::setId(int _id) {
    Word::id = _id;
}
void Word::setToSccId(int _id) {
    Word::toSccId = _id;
}

int Word::getToSccId() const {
    return toSccId;
}

int Word::getId() const {
    return id;
}

Word::~Word() = default;

char toLower(char c) {
    return (char)tolower(c);
}

void toLowerCase(std::string& str) {
    std::transform(str.begin(), str.end(), str.begin(), toLower);
}

int genWordFromList(vector<string> &wordList, vector<Word> &edges) {
    for (auto& str : wordList) {
        toLowerCase(str);
    }
    set<string> list(wordList.begin(), wordList.end());
    for (const auto &i: list) {
        edges.emplace_back(i);
    }
    return 0;
}